package com.mindata.blockchain.socket.client;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.tio.client.ClientGroupContext;
import org.tio.core.Aio;

import com.mindata.blockchain.ApplicationContextProvider;
import com.mindata.blockchain.core.event.ClientRequestEvent;
import com.mindata.blockchain.socket.common.Const;
import com.mindata.blockchain.socket.packet.BlockPacket;

/**
 * 发送消息的工具类
 * 
 * @author wuweifeng wrote on 2018/3/12.
 */
@Component
public class PacketSender {
	@Resource
	private ClientGroupContext clientGroupContext;

	public void sendGroup(final BlockPacket blockPacket) {
		//对外发出client请求事件
		ApplicationContextProvider.publishEvent(new ClientRequestEvent(blockPacket));
		//发送到一个group
		Aio.sendToGroup(clientGroupContext, Const.GROUP_NAME, blockPacket);
	}

}
